<template>
  <div class="member-container">
    <div class="page-top-form">
      <el-form :inline="true" class="query-form" ref="queryFormRef" :model="queryForm" label-position="left" status-icon size="small">
        <el-form-item label="商品名称" prop="name">
          <el-input v-model="queryForm.name" clearable placeholder="请输入商品名称" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="queryForm.phone" clearable placeholder="请输入手机号"/>
        </el-form-item>
        <el-form-item label="时间" prop="time">
          <el-date-picker v-model="queryForm.time" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" size="small" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSearch(1)" icon="el-icon-search" size="small">查 询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onReset(1)" icon="el-icon-refresh" size="small">重 置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="page-content">
      <el-table ref="myTable" :data="tableData" :header-cell-style="{background:'#f2f3f5'}" height="calc(100% - 40px)" border style="width:100%;" size="small">
        <el-table-column type="index" label="序号" width="50" align="center" />
        <el-table-column v-for="(item, index) in tableColumns" :key="index" :prop="item.prop" :label="item.label" :min-width="item.minWidth" :show-overflow-tooltip="true" align="center">
          <template slot-scope="scope">
            <div v-if="item.prop === 'status'">
              <span v-if="scope.row[item.prop] === 1" style="color: #409EFF;">正常</span>
              <span v-if="scope.row[item.prop] === 2" style="color: #f56c6c;">禁用</span>
            </div>
            <div v-else-if="item.prop === 'time'">
              <span>{{ Moment(scope.row[item.prop]).format('YYYY-MM-DD HH:mm:ss')}}</span>
            </div>
            <div v-else>
              <span>{{ scope.row[item.prop] }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100" align="center">
          <template slot-scope="scope">
            <el-button type="primary" @click="onDetails(scope.row)" size="small">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="margin-top: 10px;">
        <el-pagination :total="total" layout="total, sizes, prev, pager, next, jumper"
          :current-page="page"
          :page-sizes="pageSizes"
          :page-size="pageSize"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import Moment from 'moment'
import {pageSizes} from '@/utils/table'
export default {
  name: '订单列表',
  components: {
    Moment,
  },
  data() {
      return {
        Moment,
        queryForm: {
          name: '',
          phone: '',
          time: [this.$moment().startOf('day'), this.$moment().endOf('day')],
        },
        page: 1,
        pageSize: 20,
        pageSizes,
        total: 0,
        tableColumns: [
          { prop: 'name', label: '商品名称', minWidth: '10%' },
          { prop: 'cardNum', label: '用户姓名', minWidth: '10%' },
          { prop: 'phone', label: '手机号', minWidth: '10%' },
          { prop: 'money', label: '地址', minWidth: '10%' },
          { prop: 'point', label: '商品数量', minWidth: '10%' },
          { prop: 'status', label: '商品金额', minWidth: '10%' },
          { prop: 'status', label: '支付方式', minWidth: '10%' },
          { prop: 'status', label: '状态', minWidth: '10%' },
          { prop: 'status', label: '预检图片', minWidth: '10%' },
          { prop: 'time', label: '时间', minWidth: '15%' },
        ],
        tableData: [
          {name: '用户1', cardNum: '123456789', phone: '18512345678', money: 100, point: 20, status: 1, time: '2023-12-26 11:22:33'},
          {name: '用户2', cardNum: '987654321', phone: '18512345678', money: 100, point: 20, status: 2, time: 123456789},
          {name: '用户2', cardNum: '987654321', phone: '18512345678', money: 100, point: 20, status: 2, time: 123456789},
          {name: '用户2', cardNum: '987654321', phone: '18512345678', money: 100, point: 20, status: 2, time: 123456789},
          {name: '用户2', cardNum: '987654321', phone: '18512345678', money: 100, point: 20, status: 2, time: 123456789},
          {name: '用户2', cardNum: '987654321', phone: '18512345678', money: 100, point: 20, status: 2, time: 123456789},
          {name: '用户2', cardNum: '987654321', phone: '18512345678', money: 100, point: 20, status: 2, time: 123456789},
          {name: '用户2', cardNum: '987654321', phone: '18512345678', money: 100, point: 20, status: 2, time: 123456789},
          {name: '用户2', cardNum: '987654321', phone: '18512345678', money: 100, point: 20, status: 2, time: 123456789},
          {name: '用户2', cardNum: '987654321', phone: '18512345678', money: 100, point: 20, status: 2, time: 123456789},
        ],
      }
    },
    mounted() {
      this.onSearch(1)
    },
    methods: {
      //重置
      onReset() {
        this.$refs['queryFormRef'].resetFields()
        this.page = 1
        this.onSearch(1)
      },
      //查询
      onSearch(page) {
        this.page = page ? page : this.page
      },
      //详情
      onDetails(row) {
        this.dialogVisible = true
        
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.onSearch()
      },
      handleCurrentChange(val) {
        this.page = val
        this.onSearch()
      },
    }
}
</script>

<style lang="scss" scoped>
.member-container{
  width: 100%;
  height: 100%;
  .page-top-form{
    width: 100%;
    height: 50px;
  }
  .page-content{
    width: 100%;
    height: calc(100% - 50px);
  }
}
</style>
